package com.bharatonjava.hospital.dto;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.bharatonjava.hospital.domain.Address;
import com.bharatonjava.hospital.domain.Patient;
import com.bharatonjava.hospital.utils.Constants;

public class SearchDto {

	private Patient patient;
	private Address address;

	public SearchDto() {
	}

	public Patient getPatient() {
		return patient;
	}

	public void setPatient(Patient patient) {
		this.patient = patient;
	}

	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public Long getPatientAge() {
		Long years = 0l;
		try {
			DateFormat formatter = new SimpleDateFormat(Constants.DATE_FORMAT);
			Date birthDate = formatter.parse(patient.getDob());
			Date today = new Date();
			
			years = ((today.getTime() - birthDate.getTime())/(1000*60*60*24))/365;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return years;
	}
}
